<template>
    <div>
        <div class="ele-page-header">
            <div class="ele-page-title">系统基础配置</div>
            <div class="ele-page-desc">
                用于系统基础展示等场景。
            </div>
        </div>
        <div class="ele-body" style="padding-bottom: 71px">
            <el-form
                    ref="form"
                    :model="form"
                    :rules="rules"
                    label-width="130px"
                    @keyup.enter.native="submit"
                    @submit.native.prevent
            >
              


        
                 <el-card shadow="never" header="扣子token配置" body-style="padding: 22px 22px 0 22px;">
                    <el-row :gutter="15">
                        <el-col :lg="8" :md="12">

                            
                <el-form-item label="是否开启智能体:" prop="kouzhi_swich">
                  <el-radio-group v-model="form.kouzhi_swich">
                    <el-radio label="1" value="1">开启</el-radio>
                    <el-radio label="2" value="2">关闭</el-radio>
                  </el-radio-group>
                </el-form-item>

                            <el-form-item label="token值:" prop="kouzhi_token">
                                <el-input v-model="form.kouzhi_token" placeholder="token值" clearable/>
                            </el-form-item>


        <el-form-item label="有效时间:" prop="kouzhi_expires_in"   >
                <el-date-picker
                        v-model="form.kouzhi_expires_in"
                        type="datetime"
						 value-format="yyyy-MM-dd HH:mm:ss"
                        placeholder="选择日期时间">
                </el-date-picker>
          </el-form-item>
                        </el-col>

                    </el-row>

                </el-card>

              
              




                


                <!-- 底部工具栏 -->
                <div class="ele-bottom-tool">
                    <div v-if="validMsg" class="ele-text-danger">
                        <i class="el-icon-circle-close"></i>
                        <span>{{ validMsg }}</span>
                    </div>
                    <div class="ele-bottom-tool-actions">
                        <el-button type="primary" :loading="loading" @click="submit">
                            提交
                        </el-button>
                    </div>
                </div>
            </el-form>
        </div>
    </div>

</template>

<script>
    const DEFAULT_FORM = {
        logo_title: '',
        kouzhi_swich:'',
        

    };
    import EleImageUpload from 'ele-admin/es/ele-image-upload';
    import request from '@/utils/request';
    import uploadPictures from "@/components/uploadPictures";
    import {save, query} from '@/api/system/config';
    import TinymceEditor from '@/components/TinymceEditor';

    export default {
        name: 'SysBase',
        components: {EleImageUpload, uploadPictures, TinymceEditor},
        data() {
            return {
                modalTitle: '',
                modalPic: false,
                isChoice: "单选",
                gridBtn: {
                    xl: 4,
                    lg: 8,
                    md: 8,
                    sm: 8,
                    xs: 8,
                },
                gridPic: {
                    xl: 6,
                    lg: 8,
                    md: 12,
                    sm: 12,
                    xs: 12,
                },
                // 表单提交状态
                loading: false,
                // 表单数据
                form: {
                    ...DEFAULT_FORM
                },
                // 表单验证规则
                rules: {},
                // 表单验证信息
                validMsg: '',
                editorConfig: {
                    height: 525,
                    relative_urls: false,
                    convert_urls: false,
                    images_upload_handler: (blobInfo, success, error) => {
                        const file = blobInfo.blob();
                        // 使用 axios 上传，实际开发这段建议写在 api 中再调用 api
                        const formData = new FormData();
                        formData.append('file', file, file.name);
                        request({
                            url: '/common/uploadFile',
                            method: 'post',
                            data: formData,
                            onUploadProgress: (e) => {  // 文件上传进度回调

                            }
                        }).then((res) => {
                            if (res.data.code === 0) {
                                success(res.data.data.url);
                            } else {
                                error(res.data.message);
                            }
                        }).catch((e) => {
                            error('exception');
                        });
                    }
                },

            };
        },
        mounted() {
            query({group: 'site'}).then((msg) => {
                if (msg != null) {
                    this.form = msg;
                }
            })
                .catch((e) => {
                    this.$message.error(e.message);
                });
        },
        methods: {
            // 选择图片
            modalPicTap(tit, picTit, openTitle) {
                this.modalTitle = openTitle;
                this.isChoice = tit === "dan" ? "单选" : "多选";
                this.picTit = picTit;
                this.modalPic = true;
            },
            // 选中图片
            getPic(pc) {
                switch (this.picTit) {
                    case "site_image":
                        this.form.site_image = pc.satt_dir;
                        break;
                    case "site_login_background":
                        this.form.site_login_background = pc.satt_dir;
                        break;
                    case "merchant_img":
                        this.form.merchant_img = pc.satt_dir;
                        break;
                    case "site_ico":
                        this.form.site_ico = pc.satt_dir;
                        break;
                    case "kf_img":
                        this.form.kf_img = pc.satt_dir;
                        break;
                    case "site_login_image":
                        this.form.site_login_image = pc.satt_dir;
                        break;
                }
                this.modalPic = false;
            },
            //删除图片
            handleRemove(field) {
                this.form[field] = '';
            },
            /* 表单提交 */
            submit() {
                this.$refs['form'].validate((valid, obj) => {
                    if (valid) {
                        this.validMsg = '';
                        this.loading = true;
                        const data = {
                            ...this.form
                        };
                        save(data).then((msg) => {
                            this.loading = false;
                            this.$message.success(msg);
                        }).catch((e) => {
                            this.loading = false;
                            this.$message.error(e.message);
                        });
                    } else {
                        this.validMsg = ` 共有校验 ${Object.keys(obj).length} 项不通过`;
                        return false;
                    }
                });
            },
            onUpload(item) {
                console.log('item:', item);
                item.status = 'uploading';
                const formData = new FormData();
                formData.append('file', item.file);
                request({
                    url: '/common/uploadFile',
                    method: 'post',
                    data: formData,
                    onUploadProgress: (e) => {  // 文件上传进度回调
                        if (e.lengthComputable) {
                            item.progress = e.loaded / e.total * 100;
                        }
                    }
                }).then((res) => {
                    if (res.data.code === 0) {
                        item.status = 'done';
                        item.url = res.data.data.url;
                        // 如果你上传的不是图片格式, 建议将 url 字段作为缩略图, 再添加其它字段作为最后提交数据
                        //item.url = res.data.data.thumbnail;  // 也可以不赋值 url 字段, 默认会显示为一个文件图标
                        item.fileUrl = res.data.data.url;
                    }
                }).catch((e) => {
                    item.status = 'exception';
                });
            }
        }
    };
</script>
